#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
import shutil

gamedir = "E:/gamecopy"
backupdir = "E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2/temp"

#检查资源相关的目录是否存在
def checkDirExist():
	if(False == os.path.exists(gamedir)):
		print( gamedir + " is not exist")
		raise( gamedir + " is not exist")
	if(False == os.path.exists(backupdir)):
		print( backupdir + " is not exist")
		raise( backupdir + " is not exist")

#copy文件
def copyFileSafety(backupfile,desfile):
	if( True == os.path.exists(backupfile) ):
		if( True == os.path.exists(desfile) ):
			os.remove(desfile)
		shutil.copyfile(backupfile,desfile)

#调整资源
def channelCustomOperBegin():
	print("begin , this is lenovo !")
	checkDirExist()

	#替换图标
	lenovoIcon = backupdir + "/lenovo/icon_lenovo.png"
	gameIcon = gamedir + "/res/drawable/icon.png"
	gameIcon_hdpi = gamedir + "/res/drawable-hdpi/icon.png"
	gameIcon_ldpi = gamedir + "/res/drawable-ldpi/icon.png"
	gameIcon_mdpi = gamedir + "/res/drawable-mdpi/icon.png"
	gameIcon_xhpi = gamedir + "/res/drawable-xhdpi/icon.png"
	gameIcon_xxhpi = gamedir + "/res/drawable-xxhdpi/icon.png"
	copyFileSafety(lenovoIcon,gameIcon)
	copyFileSafety(lenovoIcon,gameIcon_hdpi)
	copyFileSafety(lenovoIcon,gameIcon_ldpi)
	copyFileSafety(lenovoIcon,gameIcon_mdpi)
	copyFileSafety(lenovoIcon,gameIcon_xhpi)
	copyFileSafety(lenovoIcon,gameIcon_xxhpi)

#恢复资源
def channelCustomOperEnd():
	print("end , this is lenovo !")
	checkDirExist()

	#还原图标
	commonIcon = backupdir + "/icon_normal.png"
	gameIcon = gamedir + "/res/drawable/icon.png"
	gameIcon_hdpi = gamedir + "/res/drawable-hdpi/icon.png"
	gameIcon_ldpi = gamedir + "/res/drawable-ldpi/icon.png"
	gameIcon_mdpi = gamedir + "/res/drawable-mdpi/icon.png"
	gameIcon_xhpi = gamedir + "/res/drawable-xhdpi/icon.png"
	gameIcon_xxhpi = gamedir + "/res/drawable-xxhdpi/icon.png"
	copyFileSafety(commonIcon,gameIcon)
	copyFileSafety(commonIcon,gameIcon_hdpi)
	copyFileSafety(commonIcon,gameIcon_ldpi)
	copyFileSafety(commonIcon,gameIcon_mdpi)
	copyFileSafety(commonIcon,gameIcon_xhpi)
	copyFileSafety(commonIcon,gameIcon_xxhpi)

if __name__=="__main__":
	if(sys.argv[1] == "begin"):
		channelCustomOperBegin()
	elif(sys.argv[1] == "end"):
		channelCustomOperEnd()
	else:
		raise("call channel custom operation must with param begin or end!")

#	channelCustomOperBegin()
#	channelCustomOperEnd()

